local skel = fk.CreateSkill{
  name = "lb__mosuo",
}

local DIY = require "packages.diy_utility.diy_utility"

Fk:loadTranslationTable{
  ["lb__mosuo"] = "摩挲",
  [":lb__mosuo"] = "每回合每名角色限一次，你可以明置一名没有「<b>丝</b>」的角色一张手牌以视为对其使用一张雷【杀】。因此明置的牌称为「<b>丝</b>」，「<b>丝</b>」不能被使用/打出/弃置且不计入手牌上限。",

  ["@@lb__mosuo-inhand"] = "丝",
  ["#lb__mosuo"] = "摩挲：你可以明置一名没有「<b>丝</b>」的角色一张手牌，视为对其使用雷【杀】",
  ["#lb__mosuo_ask"] = "摩挲：明置 %src 一张手牌为「<b>丝</b>」，视为对其使用雷【杀】",

  ["$lb__mosuo1"] = "很快就好。 ",
  ["$lb__mosuo2"] = "记住还能呼吸的感觉。",
  ["$lb__mosuo3"] = "看他们蠢蠢欲动的样子。 ",
}


skel:addEffect("viewas", {
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#lb__mosuo",
  filter_pattern = {
    min_num = 1,
    max_num = 1,
    pattern = ".",
  },
  card_filter = Util.FalseFunc,
  view_as = function(self, player, cards)
    return nil
  end,
  target_filter = function (self, player, to_select, selected, selected_cards, card, extra_data)
    local slash = Fk:cloneCard("thunder__slash")
    slash.skillName = skel.name
    return #selected == 0 and not table.find(to_select:getCardIds("h"), function (id)
        return Fk:getCardById(id):getMark("@@lb__mosuo-inhand") > 0
      end) and player:canUseTo(slash, to_select) and
      not table.contains(player:getTableMark("lb__mosuo-turn"), to_select.id)
  end,
  on_use = function(self, room, skillUseEvent, _, params)
    local player = skillUseEvent.from
    local to = skillUseEvent.tos[1]
    local ids = to:getCardIds("h")
    if #ids > 0 then
      local si = Fk:getCardById(room:askToChooseCard(player, {
        target = to,
        flag = "h",
        skill_name = skel.name,
        prompt = "#lb__mosuo_ask:"..to.id,
      }))
      room:setCardMark(si, "@@lb__mosuo-inhand", 1)
      DIY.showCards(to, si)
      room:addTableMark(player, "lb__mosuo-turn", to.id)
      local card = Fk:cloneCard("thunder__slash")
      card.skillName = skel.name
      return {  ---@type UseCardDataSpec
        from = player,
        tos = {to},
        card = card,
      }
    end
  end,
  feasible = function(self, player, selected, selected_cards, card)
    return #selected == 1
  end,
  enabled_at_play = function (self, player)
    return table.find(Fk:currentRoom().alive_players, function (to)
      return not table.contains(player:getTableMark("lb__mosuo-turn"), to.id) and 
      not table.find(to:getCardIds("h"), function (id)
        return Fk:getCardById(id):getMark("@@lb__mosuo-inhand") > 0
      end)
    end)
  end,
  enabled_at_response = Util.FalseFunc,
})

skel:addEffect("prohibit", {
  prohibit_use = function (self, player, card)
    if card:getMark("@@lb__mosuo-inhand") > 0 then
      return Fk.currentResponseReason ~= "lb__xuanye"
    end
  end,
  prohibit_response = function (self, player, card)
    if card:getMark("@@lb__mosuo-inhand") > 0 then
      return true
    end
  end,
  prohibit_discard = function (self, player, card)
    if card:getMark("@@lb__mosuo-inhand") > 0 then
      return true
    end
  end,
})

skel:addEffect("maxcards", {
  exclude_from = function (self, player, card)
    if card:getMark("@@lb__mosuo-inhand") > 0 then
      return true
    end
  end
})

return skel